// 1.有一个交通工具接口类Vehicles，有work接口
// 有Horse类和Boat类分别实现Vehicles创建交通工具工厂类，
// 有两个方法分别获得交通工具Horse和Boat有Person类，有name和Vehicles属性，
// 在构造器中为两个属性赋值实例化Person对象“唐僧”，
// 要求一般情况下用Horse作为交通工具遇到大河时用Boat作为交通工具

public class exercise06 {
    public static void main(String[] args) {
        Person p1 = new Person("tangsen", null);
        int condition = 1;
        if (condition == 0){
            p1.v1 = VehiclesFactory.getHorse();
        }else{
            p1.v1 = VehiclesFactory.getBoat();
        }
        p1.v1.work();
    }
}

interface Vehicles{
    void work();
}

class Horse implements Vehicles{
    public void work(){
        System.out.println("Horse");
    }
}

class Boat implements Vehicles{
    public void work(){
        System.out.println("Boat");
    }
}

class VehiclesFactory{

    public static Horse getHorse(){
        return new Horse();
    }

    public static Boat getBoat(){
        return new Boat();
    }

}

class Person{

    public String name;

    public Vehicles v1;

    public Person(String name,Vehicles v1){
        this.name = name;
        this.v1 = v1;
    }
}

